<?php
namespace controller;

class login
{
    // 测试工具PHPUnit要求一定要在这里给变量默认值，于是默认为空。
    public function login($Sname = "",$Sage = "",$tableName = "") {
        print("进入了login方法");
        $con = mysqli_connect("localhost", "root", "root", "yoga_io");
        if (!$con) {
            die('连接失败：');
        } else {
            mysqli_query($con, "SET NAMES utf8");

            $result = mysqli_query($con, "SELECT * FROM $tableName where Sname = $Sname and Sage = $Sage");
            if (!$result || mysqli_num_rows($result) == 0) {
                return "false";
            } else {
                $result_arr = mysqli_fetch_assoc($result);
                return json_encode($result_arr, JSON_UNESCAPED_UNICODE);
            }
        }
    }
}